package FactoryMode;

import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;

public class AbstractFactoryClient {

	public Scene getStage(){
		BorderPane borderPane = new BorderPane();
		borderPane.setPadding(new Insets(10, 0, 10, 20));
		Image image = new Image(getClass().getResourceAsStream("yyx.jpg"), 360, 250, false, false);
		ImageView imageView = new ImageView(image);

		FlowPane flowPane = new FlowPane();
		flowPane.setPadding(new Insets(0, 10, 10, 0));
		flowPane.setHgap(20);
		flowPane.setVgap(20);
		Text text1 = new Text("姓名：杨宜鑫");
		text1.setFont(Font.font("Verdana", FontWeight.BOLD, 20));
		Text text2 = new Text("学号：201627020125");
		text2.setFont(Font.font("Verdana", FontWeight.BOLD, 20));
		ChoiceBox cb1 = new ChoiceBox(FXCollections.observableArrayList("PICC",
				"PingAn"));
		ChoiceBox cb2 = new ChoiceBox(FXCollections.observableArrayList("BodilyInjury",
				"AutomobileDamage", "Casualties", "MultipleAccidents"));
		String [] greeting = {"驾驶员身体受伤","汽车损坏","人员伤亡","多种事故",};
		String [] gStrings = {"中国人寿保险","平安保险"};
		Label label1 = new Label();
		Label label2 = new Label();
		label1.setFont(new Font("Arial", 30));
		label1.setPadding(new Insets(0, 0, 40, 20));
		label2.setFont(new Font("Arial", 30));
		label2.setPadding(new Insets(0, 0, 40, 20));
		cb1.getSelectionModel().selectedIndexProperty().addListener((ov,oldv,newv)->{
			label1.setText(gStrings[newv.intValue()]);
			if(gStrings[newv.intValue()].equals("中国人寿保险")){
				cb2.getSelectionModel().selectedIndexProperty().addListener((ov1,oldv1,newv1)->{
					label2.setText(greeting[newv1.intValue()]);
					if(greeting[newv1.intValue()].equals("驾驶员身体受伤")){
						Factory factory;
						factory = new FactoryA();
						factory.createInsure();
						factory.createProduct().imformation();
					}
					else if(greeting[newv1.intValue()].equals("汽车损坏")){
						Factory factory;
						factory = new FactoryB();
						factory.createInsure();
						factory.createProduct().imformation();
					}
					else if(greeting[newv1.intValue()].equals("人员伤亡")){
						Factory factory;
						factory = new FactoryC();
						factory.createInsure();
						factory.createProduct().imformation();
					}
					else if(greeting[newv1.intValue()].equals("多种事故")){
						Factory factory;
						factory = new FactoryD();
						factory.createInsure();
						factory.createProduct().imformation();
					}
				});
			}
			else if(gStrings[newv.intValue()].equals("平安保险")){
				cb2.getSelectionModel().selectedIndexProperty().addListener((ov2,oldv2,newv2)->{
					label2.setText(greeting[newv2.intValue()]);
					if(greeting[newv2.intValue()].equals("驾驶员身体受伤")){
						Factory factory;
						factory = new Factory_A();
						factory.createInsure();
						factory.createProduct().imformation();
					}
					else if(greeting[newv2.intValue()].equals("汽车损坏")){
						Factory factory;
						factory = new Factory_B();
						factory.createInsure();
						factory.createProduct().imformation();
					}
					else if(greeting[newv2.intValue()].equals("人员伤亡")){
						Factory factory;
						factory = new Factory_C();
						factory.createInsure();
						factory.createProduct().imformation();
					}
					else if(greeting[newv2.intValue()].equals("多种事故")){
						Factory factory;
						factory = new Factory_D();
						factory.createInsure();
						factory.createProduct().imformation();
					}
				});
			}
		});
		flowPane.getChildren().addAll(text1, text2, cb1, cb2);

		borderPane.setLeft(imageView);
		borderPane.setRight(flowPane);
		borderPane.setBottom(label2);

		Scene scene = new Scene(borderPane, 900, 600);
		return scene;
	}
}
